package com.ruoyi.moon.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.vo.UpdatePasswordVO;
import com.ruoyi.common.core.domain.vo.UserInformationVO;
import com.ruoyi.common.core.domain.vo.UserVoStatisticVo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.moon.mapper.MoonCompanyMapper;
import com.ruoyi.moon.mapper.MoonReviewsMapper;
import com.ruoyi.moon.mapper.MoonUpvoteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.moon.mapper.MoonUserMapper;
import com.ruoyi.common.core.domain.entity.MoonUser;
import com.ruoyi.moon.service.IMoonUserService;

/**
 * 用户管理Service业务层处理
 * 
 * @author admin
 * @date 2024-11-05
 */
@Service
public class MoonUserServiceImpl implements IMoonUserService 
{
    @Autowired
    private MoonUserMapper moonUserMapper;

    @Autowired
    private MoonCompanyMapper moonCompanyMapper;

    @Autowired
    private MoonUpvoteMapper moonUpvoteMapper;

    @Autowired
    private MoonReviewsMapper moonReviewsMapper;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询用户管理
     * 
     * @param id 用户管理主键
     * @return 用户管理
     */
    @Override
    public MoonUser selectMoonUserById(Long id)
    {
        return moonUserMapper.selectMoonUserById(id);
    }

    /**
     * 查询用户管理列表
     * 
     * @param moonUser 用户管理
     * @return 用户管理
     */
    @Override
    public List<MoonUser> selectMoonUserList(MoonUser moonUser)
    {
        return moonUserMapper.selectMoonUserList(moonUser);
    }

    /**
     * 新增用户管理
     * 
     * @param moonUser 用户管理
     * @return 结果
     */
    @Override
    public int insertMoonUser(MoonUser moonUser)
    {
        moonUser.setCreateTime(DateUtils.getNowDate());
        return moonUserMapper.insertMoonUser(moonUser);
    }

    /**
     * 修改用户管理
     * 
     * @param moonUser 用户管理
     * @return 结果
     */
    @Override
    public int updateMoonUser(MoonUser moonUser)
    {
        return moonUserMapper.updateMoonUser(moonUser);
    }

    /**
     * 批量删除用户管理
     * 
     * @param ids 需要删除的用户管理主键
     * @return 结果
     */
    @Override
    public int deleteMoonUserByIds(Long[] ids)
    {
        return moonUserMapper.deleteMoonUserByIds(ids);
    }

    /**
     * 删除用户管理信息
     * 
     * @param id 用户管理主键
     * @return 结果
     */
    @Override
    public int deleteMoonUserById(Long id)
    {

        return moonUserMapper.deleteMoonUserById(id);
    }
//    @Override
//    public MoonUser getUserByOpenId(String openId)
//    {
//
//        return moonUserMapper.getUserByOpenId(openId);
//    }
    @Override
    public MoonUser getUserByPhone(String phone)
    {

        return moonUserMapper.getUserByPhone(phone);
    }

    @Override
    public int UpdateStatus(MoonUser moonUser) {

        return moonUserMapper.UpdateStatus(moonUser);
    }

    @Override
    public UserInformationVO selectMoonUserInformation(Long id) {
        return moonUserMapper.selectMoonUserInformation(id);
    }

    @Override
    public int updateInfo(MoonUser moonUser) {
        return moonUserMapper.updateInfo(moonUser);
    }

    @Override
    public boolean checkUserNameUnique(MoonUser user) {
        Long userId = StringUtils.isNull(user.getId()) ? -1L : user.getId();
        MoonUser info = moonUserMapper.checkUserNameUnique(user.getPhoneNumber());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 注册用户信息
     *
     * @param user 用户信息
     * @return 结果
     */
    @Override
    public boolean registerUser(MoonUser user)
    {
        user.setCreateTime(new Date());
        return moonUserMapper.insertMoonUser(user) > 0;
    }

    @Override
    public int updatePassword(UpdatePasswordVO updatePasswordVO) {

        return moonUserMapper.updatePassword(updatePasswordVO);
    }

    @Override
    public int changePassword(MoonUser moonUser) {
        return moonUserMapper.changePassword(moonUser);
    }

    @Override
    public UserVoStatisticVo statisticChannel(UserVoStatisticVo moonUser) {
        return moonUserMapper.statisticChannel(moonUser);
    }


}
